/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import acc.AdministrationInteraction;
import acc.DataInteraction;
import acc.LoginInteraction;
import acc.Validation;
import entity.User;
import java.awt.Color;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.JTextComponent;

/**
 *
 * @author Infotech
 */
public class Administrator extends javax.swing.JPanel {

    /**
     * Creates new form Administrator
     */
    public Administrator() {
        initComponents();
        fillTable();
        tblAdministration.setSelectionForeground(new Color(240, 249, 255));
        DataInteraction.readToComboBox("[Group]", cboGroupName1, "GroupName"); // read Group Name to combo box
//        DataInteraction.readToComboBox("[Group]", cboPermisson1, "Permission");
        btnEnable.setVisible(false);
        lblUserID1.setVisible(false);
        txtUserID1.setVisible(false);
        cboGroupName1.setSelectedItem(jLabel3);
        txtGroupID1.setVisible(false);
        lblGroupID1.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scpAdmin = new javax.swing.JScrollPane();
        tblAdministration = new javax.swing.JTable();
        btnHelp = new javax.swing.JButton();
        btnSearch = new javax.swing.JButton();
        txtSearchUserName = new javax.swing.JTextField();
        lblSearchCampaign = new javax.swing.JLabel();
        lblBanner = new javax.swing.JLabel();
        pnlAdmin1 = new javax.swing.JPanel();
        txtUserID1 = new javax.swing.JTextField();
        lblUserID1 = new javax.swing.JLabel();
        lblUserName1 = new javax.swing.JLabel();
        txtUserName1 = new javax.swing.JTextField();
        lblGroupName2 = new javax.swing.JLabel();
        lblGroupID1 = new javax.swing.JLabel();
        lblFullname1 = new javax.swing.JLabel();
        txtGroupID1 = new javax.swing.JTextField();
        txtFirstName1 = new javax.swing.JTextField();
        lblPassword1 = new javax.swing.JLabel();
        lblConfirmPass1 = new javax.swing.JLabel();
        cboGroupName1 = new javax.swing.JComboBox();
        txtConfirmPassword1 = new javax.swing.JPasswordField();
        txtPassword1 = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        txtLastName1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtPhone1 = new javax.swing.JTextField();
        lblGroupName3 = new javax.swing.JLabel();
        cboPermisson1 = new javax.swing.JComboBox();
        lblGender1 = new javax.swing.JLabel();
        cboGender1 = new javax.swing.JComboBox();
        txtBirthDate1 = new javax.swing.JTextField();
        lblBirthday1 = new javax.swing.JLabel();
        lblEmail1 = new javax.swing.JLabel();
        txtEmail1 = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        txaAddress1 = new javax.swing.JTextArea();
        lblAddress1 = new javax.swing.JLabel();
        btnCreate1 = new javax.swing.JButton();
        btnRefresh1 = new javax.swing.JButton();
        btnUpdate1 = new javax.swing.JButton();
        btnDelete1 = new javax.swing.JButton();
        btnDisable = new javax.swing.JButton();
        btnEnable = new javax.swing.JButton();
        btnChangePass = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setMinimumSize(new java.awt.Dimension(1020, 700));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }
        });

        scpAdmin.setBackground(new java.awt.Color(255, 255, 255));
        scpAdmin.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tblAdministration.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        tblAdministration.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblAdministration.setFocusable(false);
        tblAdministration.setGridColor(new java.awt.Color(255, 255, 255));
        tblAdministration.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblAdministrationMouseClicked(evt);
            }
        });
        scpAdmin.setViewportView(tblAdministration);

        btnHelp.setBackground(new java.awt.Color(255, 255, 255));
        btnHelp.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnHelp.setForeground(new java.awt.Color(3, 97, 145));
        btnHelp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_Help.png"))); // NOI18N
        btnHelp.setText("Help");
        btnHelp.setContentAreaFilled(false);
        btnHelp.setFocusable(false);
        btnHelp.setMargin(new java.awt.Insets(2, 2, 2, 2));
        btnHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHelpActionPerformed(evt);
            }
        });

        btnSearch.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnSearch.setForeground(new java.awt.Color(3, 97, 145));
        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_search.png"))); // NOI18N
        btnSearch.setText("Search");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        txtSearchUserName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtSearchUserName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtSearchUserNameKeyReleased(evt);
            }
        });

        lblSearchCampaign.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblSearchCampaign.setText("User Name:");

        lblBanner.setBackground(new java.awt.Color(255, 255, 255));
        lblBanner.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/tit_admin.jpg"))); // NOI18N

        pnlAdmin1.setBackground(new java.awt.Color(255, 255, 255));
        pnlAdmin1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 103, 0)));
        pnlAdmin1.setMinimumSize(new java.awt.Dimension(500, 700));

        txtUserID1.setBackground(new java.awt.Color(240, 249, 255));
        txtUserID1.setEditable(false);
        txtUserID1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtUserID1.setForeground(new java.awt.Color(3, 97, 145));
        txtUserID1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUserID1ActionPerformed(evt);
            }
        });

        lblUserID1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblUserID1.setText("User ID:");

        lblUserName1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblUserName1.setText("User Name:");

        txtUserName1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblGroupName2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGroupName2.setText("Group Name:");

        lblGroupID1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGroupID1.setText("Group ID:");

        lblFullname1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblFullname1.setText("FirstName:");

        txtGroupID1.setBackground(new java.awt.Color(240, 249, 255));
        txtGroupID1.setEditable(false);
        txtGroupID1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtGroupID1.setForeground(new java.awt.Color(3, 97, 145));
        txtGroupID1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtGroupID1ActionPerformed(evt);
            }
        });

        txtFirstName1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblPassword1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblPassword1.setText("Password:");

        lblConfirmPass1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblConfirmPass1.setText("Confirm Pass:");

        cboGroupName1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cboGroupName1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        cboGroupName1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboGroupName1ActionPerformed(evt);
            }
        });

        txtConfirmPassword1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        txtPassword1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("LastName:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Phone:");

        lblGroupName3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGroupName3.setText("Permission: ");

        cboPermisson1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cboPermisson1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrator", "Campaign master", "Product master", "Estimate budget", "Actual budget", "Statistics", "Read only", " " }));
        cboPermisson1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        cboPermisson1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboPermisson1ActionPerformed(evt);
            }
        });

        lblGender1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGender1.setText("Gender:");

        cboGender1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cboGender1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));

        txtBirthDate1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblBirthday1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblBirthday1.setText("Birdhday:");

        lblEmail1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEmail1.setText("Email:");

        txtEmail1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jScrollPane3.setBackground(new java.awt.Color(255, 255, 255));
        jScrollPane3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));

        txaAddress1.setColumns(20);
        txaAddress1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txaAddress1.setLineWrap(true);
        txaAddress1.setRows(2);
        txaAddress1.setWrapStyleWord(true);
        jScrollPane3.setViewportView(txaAddress1);

        lblAddress1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblAddress1.setText("Address:");

        btnCreate1.setBackground(new java.awt.Color(255, 255, 255));
        btnCreate1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnCreate1.setForeground(new java.awt.Color(3, 97, 145));
        btnCreate1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_add.png"))); // NOI18N
        btnCreate1.setText("Create");
        btnCreate1.setContentAreaFilled(false);
        btnCreate1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCreate1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCreate1.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnCreate1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreate1ActionPerformed(evt);
            }
        });

        btnRefresh1.setBackground(new java.awt.Color(255, 255, 255));
        btnRefresh1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnRefresh1.setForeground(new java.awt.Color(3, 97, 145));
        btnRefresh1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_cancel.png"))); // NOI18N
        btnRefresh1.setText("Refresh");
        btnRefresh1.setContentAreaFilled(false);
        btnRefresh1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnRefresh1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnRefresh1.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnRefresh1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefresh1ActionPerformed(evt);
            }
        });

        btnUpdate1.setBackground(new java.awt.Color(255, 255, 255));
        btnUpdate1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnUpdate1.setForeground(new java.awt.Color(3, 97, 145));
        btnUpdate1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_up.png"))); // NOI18N
        btnUpdate1.setText("Update");
        btnUpdate1.setContentAreaFilled(false);
        btnUpdate1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnUpdate1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnUpdate1.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnUpdate1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdate1ActionPerformed(evt);
            }
        });

        btnDelete1.setBackground(new java.awt.Color(255, 255, 255));
        btnDelete1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnDelete1.setForeground(new java.awt.Color(3, 97, 145));
        btnDelete1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_cancel.png"))); // NOI18N
        btnDelete1.setText("Delete");
        btnDelete1.setContentAreaFilled(false);
        btnDelete1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnDelete1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnDelete1.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnDelete1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelete1ActionPerformed(evt);
            }
        });

        btnDisable.setBackground(new java.awt.Color(255, 255, 255));
        btnDisable.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnDisable.setForeground(new java.awt.Color(3, 97, 145));
        btnDisable.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_cancel.png"))); // NOI18N
        btnDisable.setText("Disable");
        btnDisable.setContentAreaFilled(false);
        btnDisable.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnDisable.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnDisable.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnDisable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDisableActionPerformed(evt);
            }
        });

        btnEnable.setBackground(new java.awt.Color(255, 255, 255));
        btnEnable.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnEnable.setForeground(new java.awt.Color(3, 97, 145));
        btnEnable.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_cancel.png"))); // NOI18N
        btnEnable.setText("Enable");
        btnEnable.setContentAreaFilled(false);
        btnEnable.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnEnable.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEnable.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnEnable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEnableActionPerformed(evt);
            }
        });

        btnChangePass.setBackground(new java.awt.Color(255, 255, 255));
        btnChangePass.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnChangePass.setForeground(new java.awt.Color(3, 97, 145));
        btnChangePass.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_cancel.png"))); // NOI18N
        btnChangePass.setText("Change Password");
        btnChangePass.setContentAreaFilled(false);
        btnChangePass.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnChangePass.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnChangePass.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnChangePass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangePassActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlAdmin1Layout = new javax.swing.GroupLayout(pnlAdmin1);
        pnlAdmin1.setLayout(pnlAdmin1Layout);
        pnlAdmin1Layout.setHorizontalGroup(
            pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAdmin1Layout.createSequentialGroup()
                .addGap(0, 34, Short.MAX_VALUE)
                .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnlAdmin1Layout.createSequentialGroup()
                            .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblUserID1)
                                .addComponent(lblUserName1)
                                .addComponent(lblPassword1)
                                .addComponent(lblConfirmPass1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblGroupID1))
                            .addGap(10, 10, 10))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlAdmin1Layout.createSequentialGroup()
                            .addComponent(lblGroupName2)
                            .addGap(18, 18, 18)))
                    .addGroup(pnlAdmin1Layout.createSequentialGroup()
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblFullname1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(lblGroupName3)
                            .addComponent(lblGender1)
                            .addComponent(lblBirthday1)
                            .addComponent(lblEmail1)
                            .addComponent(lblAddress1))
                        .addGap(26, 26, 26)))
                .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtConfirmPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUserName1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboGroupName1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUserID1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtBirthDate1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboGender1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtGroupID1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtLastName1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFirstName1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboPermisson1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPhone1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEmail1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(44, 44, 44)
                .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnChangePass, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnRefresh1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnDisable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnEnable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnDelete1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnUpdate1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCreate1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(128, 128, 128))
        );
        pnlAdmin1Layout.setVerticalGroup(
            pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAdmin1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlAdmin1Layout.createSequentialGroup()
                        .addComponent(btnCreate1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnUpdate1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnDelete1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnEnable, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnDisable, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnChangePass, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnRefresh1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlAdmin1Layout.createSequentialGroup()
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtUserID1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblUserID1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtUserName1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblUserName1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblPassword1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblConfirmPass1)
                            .addComponent(txtConfirmPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cboGroupName1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblGroupName2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblGroupID1)
                            .addComponent(txtGroupID1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblFullname1)
                            .addComponent(txtFirstName1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtLastName1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtPhone1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblGroupName3)
                            .addComponent(cboPermisson1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblGender1)
                            .addComponent(cboGender1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblBirthday1)
                            .addComponent(txtBirthDate1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblEmail1)
                            .addComponent(txtEmail1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlAdmin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblAddress1)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(216, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblBanner, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblSearchCampaign)
                        .addGap(17, 17, 17)
                        .addComponent(txtSearchUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(btnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(scpAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, 448, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pnlAdmin1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(lblBanner, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(scpAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, 542, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(lblSearchCampaign))
                            .addComponent(txtSearchUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnHelp)))
                        .addGap(27, 27, 27))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pnlAdmin1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(7, Short.MAX_VALUE))))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void tblAdministrationMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblAdministrationMouseClicked
        if (tblAdministration.getSelectedRow() == -1) {
            new ShowMessageDialog(null, true, "Please choose a row", ShowMessageDialog.MESSAGE);
            return;
        }
        int row = tblAdministration.getSelectedRow();

        fillUserInformation((String) tblAdministration.getValueAt(row, 0));//row la hang duoc chon, column = 0 la lay truong UserID
        btnCreate1.setEnabled(false);
        lblPassword1.setVisible(false);
        lblConfirmPass1.setVisible(false);
        txtPassword1.setVisible(false);
        txtConfirmPassword1.setVisible(false);
    }//GEN-LAST:event_tblAdministrationMouseClicked

    private void btnHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHelpActionPerformed
//        new HelpDialog(null, false);
    }//GEN-LAST:event_btnHelpActionPerformed

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        String name = txtSearchUserName.getText().trim();

//        if (!Validation.validateComponents(new JTextComponent[]{txtSearchUserName})) {
//            return;
//        } else {
        try {
            DefaultTableModel model = new DefaultTableModel();
            tblAdministration.setModel(model);
            model.addColumn("User ID");
            model.addColumn("User Name");
            model.addColumn("Full Name");
            model.addColumn("Gender");
            model.addColumn("Date Of Birth");
            model.addColumn("Address");
            model.addColumn("Email");

            String sql = "Select * from [User] where UserName like '%" + name + "%'";
            PreparedStatement prs = DataInteraction.connect().prepareStatement(sql);
            ResultSet rs = prs.executeQuery();
            Vector load;
            if (rs != null) {
                while (rs.next()) {
                    load = new Vector();
                    load.add(rs.getString(1));
                    load.add(rs.getString(2));
                    load.add(rs.getString(4));
                    load.add(rs.getString(5));
                    load.add(rs.getString(6));
                    load.add(rs.getString(7));
                    load.add(rs.getString(8));
                    model.addRow(load);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //}
    }//GEN-LAST:event_btnSearchActionPerformed

    private void txtSearchUserNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSearchUserNameKeyReleased
        java.awt.event.MouseEvent ev = null;
        if (txtSearchUserName.getText().equals("")) {
            tblAdministration.setRowHeight(16);
            tblAdministration.changeSelection(0, 0, false, false);
        } else {

            for (int i = 0; i < tblAdministration.getRowCount(); i++) {
                Object o = tblAdministration.getValueAt(i, 1);
                String a = o.toString().trim().toLowerCase();
                String b = txtSearchUserName.getText().trim().toLowerCase();
                if ((a.indexOf(b) == -1) || (b.charAt(0) != a.charAt(0))) {
                    tblAdministration.setRowHeight(i, 1);

                } else {
                    tblAdministration.setRowHeight(i, 16);
                    tblAdministration.changeSelection(i, 0, false, false);
                }

            }
        }
    }//GEN-LAST:event_txtSearchUserNameKeyReleased

    private void txtUserID1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUserID1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUserID1ActionPerformed

    private void cboGroupName1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboGroupName1ActionPerformed
        String GroupID = DataInteraction.getAnotherField("[Group]", "GroupName", "GroupID", cboGroupName1.getSelectedItem().toString());
        txtGroupID1.setText(GroupID);
    }//GEN-LAST:event_cboGroupName1ActionPerformed

    private void cboPermisson1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboPermisson1ActionPerformed
//        // TODO add your handling code here:
//        String permission = DataInteraction.getAnotherField("[Role]", "Permission", "Permission", cboGroupName.getSelectedItem().toString());
//        cboPermisson1.setText(permission);
    }//GEN-LAST:event_cboPermisson1ActionPerformed

    private void btnCreate1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreate1ActionPerformed
//        if (!Validation.validateComponents(new JTextComponent[]{txtUserName, txtPassword, txtConfirmPassword, txtFirstName, txtLastName, txtPhone, txaAddress, txtBirthDate, txtEmail})) {
//            return;
//        }
        if (txtBirthDate1.getText().trim().length() > 0) {
            if (!Validation.isDate(txtBirthDate1.getText())) {
                Validation.showMessage("Date must in dd/MM/yyy format");
                txtBirthDate1.setBackground(new Color(250, 255, 168));
                txtBirthDate1.requestFocus();
                return;
            }
            if (Validation.convertStringToDate(txtBirthDate1.getText()).compareTo(new Date(System.currentTimeMillis())) >= 0) {
                Validation.showMessage("Date must be before current time");
                txtBirthDate1.setBackground(new Color(250, 255, 168));
                txtBirthDate1.requestFocus();
                return;
            }
        }
        if (!txtPassword1.getText().equals(txtConfirmPassword1.getText())) {
            Validation.showMessage("Two password must be the same");
            txtPassword1.setBackground(new Color(250, 255, 168));
            txtConfirmPassword1.setBackground(new Color(250, 255, 168));
            txtConfirmPassword1.requestFocus();
            return;
        }
        if (txtEmail1.getText().trim().length() > 0) {
            if (!Validation.isValidEmail(txtEmail1.getText())) {
                Validation.showMessage("Wrong email format");
                txtEmail1.setBackground(new Color(250, 255, 168));
                txtEmail1.requestFocus();
                return;
            }
        }
        if (Validation.isDuplicateValue("[User]", "UserName", txtUserName1.getText())) {
            Validation.showMessage("User name has existed");
            txtUserName1.setBackground(new Color(250, 255, 168));
            return;
        } else {
            txtUserName1.setBackground(Color.white);
        }

        if (Validation.isValidPhoneNumber(txtPhone1.getText())) {
            Validation.showMessage("Phone number only accept value 0-9!!!");
            txtPhone1.setBackground(new Color(250, 255, 168));
            txtPhone1.requestFocus();
            return;
        }
        User userInsertTemp = getUser();
        try {
            userInsertTemp.setUserID(AdministrationInteraction.createNewUserId());
            txtUserID1.getText();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        String result = AdministrationInteraction.insertUser(userInsertTemp);
        new ShowMessageDialog(null, true, cboPermisson1.getSelectedItem().toString().trim() + " account have been created!!!", ShowMessageDialog.MESSAGE);
//        this.dispose();
        refresh();
    }//GEN-LAST:event_btnCreate1ActionPerformed

    private void btnRefresh1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefresh1ActionPerformed
        refresh();
    }//GEN-LAST:event_btnRefresh1ActionPerformed

    private void btnUpdate1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdate1ActionPerformed
        txtBirthDate1.setBackground(Color.white);
        txtEmail1.setBackground(Color.white);
        txtGroupID1.setBackground(Color.white);
        if (tblAdministration.getSelectedRow() == -1) {
            new ShowMessageDialog(null, true, "Please choose a row", ShowMessageDialog.MESSAGE);
            return;
        }
//        if (!Validation.validateComponents(new JTextComponent[]{txtUserName, txtPassword, txtConfirmPassword, txtFullName, txtBirthDate, txtEmail})) {
//            return;
//        }
//        if (txtUserID.getText().equalsIgnoreCase("USER01") && !txtGroupID.getText().equalsIgnoreCase("GR01")) {
//            Validation.showMessage("Cannot change group of this admin.");
//            txtGroupID.setBackground(new Color(250, 255, 168));
//            return;
//        }
        if (txtBirthDate1.getText().trim().length() > 0) {
            if (!Validation.isDate(txtBirthDate1.getText())) {
                Validation.showMessage("Date must in dd/MM/yyy format");
                txtBirthDate1.setBackground(new Color(250, 255, 168));
                txtBirthDate1.requestFocus();
                return;
            }
            if (Validation.convertStringToDate(txtBirthDate1.getText()).compareTo(new Date(System.currentTimeMillis())) >= 0) {
                Validation.showMessage("Date must be before current time");
                txtBirthDate1.setBackground(new Color(250, 255, 168));
                txtBirthDate1.requestFocus();
                return;
            }
        }

        if (txtEmail1.getText().trim().length() > 0) {
            if (!Validation.isValidEmail(txtEmail1.getText())) {
                Validation.showMessage("Wrong email format");
                txtEmail1.setBackground(new Color(250, 255, 168));
                txtEmail1.requestFocus();
                return;
            }
        }

        String result = AdministrationInteraction.updateUser(getUser());
        new ShowMessageDialog(null, true, result, ShowMessageDialog.MESSAGE);
        refresh();

    }//GEN-LAST:event_btnUpdate1ActionPerformed

    private void btnDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelete1ActionPerformed
        txtGroupID1.setBackground(Color.white);
        if (tblAdministration.getSelectedRow() == -1) {
            new ShowMessageDialog(null, true, "Please choose a row", ShowMessageDialog.MESSAGE);
            return;
        }
        //Not use Delete Account Admin
        //        if(txtUserID.getText().equalsIgnoreCase("USER01"))
        //        {
        //            Validation.showMessage("Cannot delete admin user !");
        //            return;
        //        }
        new ShowMessageDialog(null, true, "Do you want to delete this user?", ShowMessageDialog.CONFIRM);
        if (ShowMessageDialog.STATUS == ShowMessageDialog.OK) {
            String result = AdministrationInteraction.deleteUser(txtUserID1.getText());
            new ShowMessageDialog(null, true, result, ShowMessageDialog.MESSAGE);
            btnCreate1.setEnabled(true);
            refresh();
        }
    }//GEN-LAST:event_btnDelete1ActionPerformed

    private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
        // TODO add your handling code here:
        refresh();
    }//GEN-LAST:event_formMousePressed

    private void txtGroupID1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtGroupID1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtGroupID1ActionPerformed

    private void btnDisableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisableActionPerformed
        // TODO add your handling code here:
        if (tblAdministration.getSelectedRow() == -1) {
            new ShowMessageDialog(null, true, "Please choose a row", ShowMessageDialog.MESSAGE);
            return;
        }
        String result = AdministrationInteraction.disable(getUser());
        new ShowMessageDialog(null, true, result, ShowMessageDialog.MESSAGE);
        refresh();

    }//GEN-LAST:event_btnDisableActionPerformed

    private void btnEnableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnableActionPerformed
        // TODO add your handling code here:
        String result = AdministrationInteraction.enable(getUser());
        new ShowMessageDialog(null, true, result, ShowMessageDialog.MESSAGE);
        refresh();
    }//GEN-LAST:event_btnEnableActionPerformed

    private void btnChangePassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangePassActionPerformed
        // TODO add your handling code here:
        if (tblAdministration.getSelectedRow() == -1) {
            new ShowMessageDialog(null, true, "Please choose a row", ShowMessageDialog.MESSAGE);
            return;
        }
        new ChangePassword(null, true);
        refresh();
    }//GEN-LAST:event_btnChangePassActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChangePass;
    private javax.swing.JButton btnCreate1;
    private javax.swing.JButton btnDelete1;
    private javax.swing.JButton btnDisable;
    private javax.swing.JButton btnEnable;
    private javax.swing.JButton btnHelp;
    private javax.swing.JButton btnRefresh1;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnUpdate1;
    private javax.swing.JComboBox cboGender1;
    private javax.swing.JComboBox cboGroupName1;
    private javax.swing.JComboBox cboPermisson1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblAddress1;
    private javax.swing.JLabel lblBanner;
    private javax.swing.JLabel lblBirthday1;
    private javax.swing.JLabel lblConfirmPass1;
    private javax.swing.JLabel lblEmail1;
    private javax.swing.JLabel lblFullname1;
    private javax.swing.JLabel lblGender1;
    private javax.swing.JLabel lblGroupID1;
    private javax.swing.JLabel lblGroupName2;
    private javax.swing.JLabel lblGroupName3;
    private javax.swing.JLabel lblPassword1;
    private javax.swing.JLabel lblSearchCampaign;
    private javax.swing.JLabel lblUserID1;
    private javax.swing.JLabel lblUserName1;
    private javax.swing.JPanel pnlAdmin1;
    private javax.swing.JScrollPane scpAdmin;
    private static javax.swing.JTable tblAdministration;
    private javax.swing.JTextArea txaAddress1;
    private javax.swing.JTextField txtBirthDate1;
    private javax.swing.JPasswordField txtConfirmPassword1;
    private javax.swing.JTextField txtEmail1;
    private javax.swing.JTextField txtFirstName1;
    private javax.swing.JTextField txtGroupID1;
    private javax.swing.JTextField txtLastName1;
    private javax.swing.JPasswordField txtPassword1;
    private javax.swing.JTextField txtPhone1;
    private javax.swing.JTextField txtSearchUserName;
    private javax.swing.JTextField txtUserID1;
    private javax.swing.JTextField txtUserName1;
    // End of variables declaration//GEN-END:variables
    Vector users = LoginInteraction.getUser();//thay getUser
    String userID = "";
    
    public static String getUserIDSelected(){
        int row = tblAdministration.getSelectedRow();
        return (String) tblAdministration.getValueAt(row, 0);
    }
    public User getUser() {
        User user = new User();
        user.setUserID(txtUserID1.getText());
        user.setUserName(txtUserName1.getText());
        user.setPassword(txtPassword1.getText());
        user.setFullName(txtFirstName1.getText());
        user.setLastName(txtLastName1.getText());
        user.setPhone(txtPhone1.getText());
        user.setGender(cboGender1.getSelectedItem().toString());
        user.setDateOfBirth(Validation.convertStringToDate(txtBirthDate1.getText()));
        user.setAddress(txaAddress1.getText());
        user.setEmail(txtEmail1.getText());
        user.setGroupID(txtGroupID1.getText());
        user.setGroupName(cboGroupName1.getSelectedItem().toString());
        user.setPermission(cboPermisson1.getSelectedItem().toString());

        return user;
    }

    private void refresh() {
        users = LoginInteraction.getUser();
        fillTable();
//        Validation.setBlankField(new JTextComponent[]{txtUserID, txtUserName, txtPassword, txtConfirmPassword, txtFullName, txtEmail, txtBirthDate, araAddress});
        cboGroupName1.setSelectedIndex(0);
        cboGender1.setSelectedIndex(1);
        btnCreate1.setEnabled(true);
        btnEnable.setVisible(false);
        btnDisable.setVisible(true);
        lblPassword1.setVisible(true);
        lblConfirmPass1.setVisible(true);
        txtPassword1.setVisible(true);
        txtConfirmPassword1.setVisible(true);
        reset();
    }

    private void fillTable() {
        Vector title = new Vector();
        title.add("User ID");
        title.add("UserName");
        title.add("Group");

        Vector campaigns = LoginInteraction.readUser();
        if (campaigns.size() > 0) {
            tblAdministration.setModel(new DefaultTableModel(campaigns, title));
            tblAdministration.getColumnModel().getColumn(0).setPreferredWidth(70);
            tblAdministration.getColumnModel().getColumn(1).setPreferredWidth(100);
            tblAdministration.getColumnModel().getColumn(2).setPreferredWidth(100);
            tblAdministration.setDragEnabled(false);
        }
    }

    private void fillUserInformation(String UserID) {
        if (users.size() > 0) {
            for (int i = 0; i < users.size(); i++) {
                Vector temp = (Vector) users.elementAt(i);
                if (UserID.equals(temp.elementAt(0).toString())) {
                    if (temp.elementAt(13).toString().trim().equalsIgnoreCase("0")) {
                        btnDisable.setVisible(false);//if user's status = false, disable button will be hided
                        btnEnable.setVisible(true);
//                        JOptionPane.showMessageDialog(this, temp.elementAt(13).toString());
                    }else{
                        btnDisable.setVisible(true);
                        btnEnable.setVisible(false);
                    }
                    txtUserID1.setText(temp.elementAt(0).toString());
                    txtUserName1.setText(temp.elementAt(1).toString());
//                    txtPassword.setText(temp.elementAt(2).toString());
                    txtFirstName1.setText(temp.elementAt(3).toString());
                    txtLastName1.setText(temp.elementAt(4).toString());
                    for (int j = 0; j < cboGender1.getItemCount(); j++) {
                        if (temp.elementAt(5).toString().equals(cboGender1.getItemAt(j).toString())) {
                            cboGender1.setSelectedIndex(j);
                            break;
                        }
                    } // end for j
                    txtBirthDate1.setText((String) temp.elementAt(6));
                    txtEmail1.setText(temp.elementAt(7).toString());
                    txtPhone1.setText(temp.elementAt(8).toString());
                    txaAddress1.setText(temp.elementAt(9).toString());
                    txtGroupID1.setText(temp.elementAt(10).toString());
                    for (int k = 0; k < cboGroupName1.getItemCount(); k++) {
                        if (temp.elementAt(11).toString().equals(cboGroupName1.getItemAt(k).toString())) {
                            cboGroupName1.setSelectedIndex(k);
                            break;
                        }
                    } // end for k
                    break;

                }

            } //end for i
        }
    }

    private void reset() {
        txtUserID1.setText("");
        txtUserName1.setText("");
        txtPassword1.setText("");
        txtConfirmPassword1.setText("");
        txtGroupID1.setText("");
        txtPhone1.setText("");
        txaAddress1.setText("");
        txtEmail1.setText("");
        txtFirstName1.setText("");
        txtLastName1.setText("");
        txtBirthDate1.setText("");
    }
}
